package com.qingfeng.core.dao.qingfeng;

import com.github.pagehelper.PageInfo;
import com.qingfeng.core.config.database.BaseMapper;
import com.qingfeng.core.dao.BaseDao;
import com.qingfeng.core.entity.qingfeng.Message;
import com.qingfeng.core.mapper.qingfeng.MessageMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

/**
 * @description: 消息
 * @author:LWY
 * @date: 2017/10/16 17:15
 * @modified:
 */

@Repository
public class MessageDao extends BaseDao<Message> {

    @Autowired
    MessageMapper messageMapper;

    @Override
    protected BaseMapper<Message> getBaseMapper() {
        return messageMapper;
    }

    /**
     * 获取用户的消息
     *
     * @param pageNum  页码
     * @param pageSize 每页显示多少页
     * @param user_id  用户id
     * @return
     */
    public PageInfo<Message> get(Integer pageNum, Integer pageSize, String user_id) {
        Example example = new Example(Message.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(user_id)) {
            //在有效期之内
            criteria.andEqualTo("user_id", user_id);
        }
        example.setOrderByClause("create_time desc");
        return super.get(pageNum, pageSize, example);
    }
}
